<?php
/**
 * Created by PhpStorm.
 * User: chongyi
 * Date: 2015/4/9
 * Time: 9:46
 */

namespace Test;


class ConvertGrowRecordComment extends Convert {
    public function convert($grow, $newid) {
        $comments = $this->connection->table('yuanbao_v1.t_picture_comment')->where('pictureId', '=', $grow->id)->get();

        foreach ($comments as $comment) {
            $userid = $this->connection->table('convert.v2_sys_user')->where('user', '=', $comment->publisherCode)->pluck('id');
            if ($userid === null) continue;
            $this->connection->table('convert.v2_school_student_grow_reply')->insert(array(
                'parent_id' => 0,
                'grow_id' => $newid,
                'user_id' => $userid,
                'content' => $comment->comment,
                'created_time' => strtotime($comment->publishTime),
                'update_time' => 0,
                'status' => 1
            ));
        }

        // 点赞
        $prasies = $this->connection->table('yuanbao_v1.t_picture_praise')->where('pictureId', '=', $grow->id)->get();
        foreach ($prasies as $prasie) {
            $userid = $this->connection->table('convert.v2_sys_user')->where('user', '=', $prasie->publisherCode)->pluck('id');
            if ($userid === null) continue;
            $this->connection->table('convert.v2_school_student_grow_praise')->insert(array(
                'grow_id' => $newid,
                'user_id' => $userid,
                'created_time' => strtotime($prasie->publishTime),
            ));
        }
    }
} 